package com.itheima.stock;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@SpringBootTest
public class EasyExcal {

    /*
    * 插入
    * */
    @Test
    void export()
    {
        updowncount build = updowncount.builder()
                .count(10)
                .time(new Date()).build();
        List<updowncount> list = new ArrayList<>();
        list.add(build);

        EasyExcel.write("C:\\Users\\86135\\Desktop\\日语四级\\test.xls", updowncount.class)
                .sheet("用户信息").doWrite(list);
    }

/*
* 读取
* */

    @Test
    void insert()
    {
        /*要无参构造器*/
        EasyExcel.read("C:\\Users\\86135\\Desktop\\日语四级\\test.xls", updowncount.class, new AnalysisEventListener<updowncount>() {
            @Override
            public void invoke(updowncount data, AnalysisContext analysisContext) {
                //这个data就是对象数据
                System.out.println(data);
            }
            /*
            * 这里就是输出完调用的方法
            * */
            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {

                System.out.println("打印完了");
            }
        }).sheet("用户信息")
                .doRead();
    }
}
